package leetcode.lcp0028;

import java.util.Arrays;

import leetcode.IDebug;

public class Solution implements IDebug {

	int mod = 1000000007;

	public int purchasePlans(int[] nums, int target) {
		Arrays.sort(nums);
		int len = nums.length;
		long ans = 0;
		for (int i = 0, j = len - 1; i < len && i < j; i++) {
			int cur = nums[i], find = target - cur;
			while (j > i && nums[j] > find) {
				j--;
			}
			ans += j - i;
			ans %= mod;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
